package DataStructure;

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

/**
 * Properties 继承于 Hashtable。表示一个持久的属性集.属性列表中每个键及其对应值都是一个字符串。
 */
public class PropertiesTest {
    
    public static void main(String[] args) {
        
        Properties capitals = new Properties();
        Set states;
        String str;
        capitals.put("Illinois", "Springfield");
        capitals.put("Missouri", "Jefferson City");
        capitals.put("Washington", "Olympia");
        capitals.put("California", "Sacramento");
        capitals.put("Indiana", "Indianapolis");

        capitals.setProperty("Indiana", "edit Indianapolis");//修改Indiana 值
        capitals.setProperty("czj", "czj");//修改czj，不存在则添加
   
        // Show all states and capitals in hashtable.
        states = capitals.keySet(); // get set-view of keys
        Iterator<String> itr = states.iterator();//迭代器 iterator
        //检查序列中是否还有元素
        while(itr.hasNext()) {
           str = (String) itr.next();//获得序列中的下一个元素
           System.out.println("The capital of " +
              str + " is " + capitals.getProperty(str) + ".");
        }
        System.out.println();
   
        // look for state not in list -- specify default
        str = capitals.getProperty("Florida", "Not Found");
        System.out.println("The capital of Florida is "
            + str + ".");
    }
}
